﻿namespace Leetcode.N0004;
public class Solution
{
    public double FindMedianSortedArrays(int[] nums1, int[] nums2)
    {
        var nums3 = new int[nums1.Length + nums2.Length];
        var index1 = 0;
        var index2 = 0;
        for (int i = 0; i < nums3.Length; i++)
        {
            if (index2 >= nums2.Length || (index1 < nums1.Length && nums1[index1] <= nums2[index2]))
            {
                nums3[i] = nums1[index1];
                index1++;
            }
            else
            {
                nums3[i] = nums2[index2];
                index2++;
            }
        }

        if (nums3.Length % 2 == 1)
        {
            return nums3[(nums3.Length - 1) / 2];
        }
        else
        {
            return (double)(nums3[nums3.Length / 2 - 1] + nums3[nums3.Length / 2]) / 2;

        }
    }
}
